package com.soft.controller;

import com.soft.pojo.User;
import com.soft.service.UserService;
import com.soft.utils.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ruoxi
 * @create 2021-12-27 18:49
 */
@WebServlet("/editUser")
public class EditUserById extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        int id = Integer.parseInt(req.getParameter("id"));
        String uname = req.getParameter("uname");
        String pwd = req.getParameter("pwd");

        UserService userService = new UserService();
        User user = new User(id,uname,pwd);

        Result result = userService.editUserById(user);

        req.setAttribute("editUserMsg", result.getMsg());
        req.getRequestDispatcher("showAllUserByPage").forward(req,resp);
    }
}
